/*
 * @Author: taoyuqing
 * @Date: 2023-02-22 00:51:41
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:spree/utils/utils.dart';
import 'package:spree/widgets/common_container.dart';
import 'package:spree/widgets/vip_rectangle_box.dart';

import '../../utils/api.dart';
import '../../utils/precision_limit_formatter.dart';

class WithdrawnPage extends StatefulWidget {
  WithdrawnPage({Key? key}) : super(key: key);

  @override
  State<WithdrawnPage> createState() => _WithdrawnPageState();
}

class _WithdrawnPageState extends State<WithdrawnPage> {
  TextEditingController _controller1 = TextEditingController();
  TextEditingController _controller2 = TextEditingController();
  TextEditingController _controller3 = TextEditingController();
  TextEditingController _controller4 = TextEditingController();
  TextEditingController _controller5 = TextEditingController();
  TextEditingController _controller6 = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('withdrawn'),
      ),
      body: CommonContainer(
        child: ListView(
          children: [
            Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                      margin: EdgeInsets.only(top: 10),
                      child: Row(
                        children: [
                          VipRectangleBox(
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 5, bottom: 5),
                            color: Color(0xFF29205F),
                            child: Text(
                              'TRC20',
                              style: TextStyle(
                                  color: Color(0xFFFFED4A),
                                  fontWeight: FontWeight.w700),
                            ),
                          ),
                          VipRectangleBox(
                            margin: EdgeInsets.only(left: 20),
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 5, bottom: 5),
                            color: Color(0xFF29205F),
                            child: Text(
                              'PIX',
                              style: TextStyle(
                                  color: Color(0xFFFFED4A),
                                  fontWeight: FontWeight.w700),
                            ),
                          ),
                          VipRectangleBox(
                            margin: EdgeInsets.only(left: 20),
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 5, bottom: 5),
                            color: Color(0xFF29205F),
                            child: Text(
                              'PICPAY',
                              style: TextStyle(
                                  color: Color(0xFFFFED4A),
                                  fontWeight: FontWeight.w700),
                            ),
                          ),
                        ],
                      )),
                  _inputBox(
                      onlyNum: true,
                      controller: _controller1,
                      title: 'Amount Withdrawn:',
                      label: 'R\$',
                      placeholder: '0.00'),
                  _inputBox(
                      controller: _controller2,
                      title: 'Cardholder Name:',
                      placeholder: 'name'),
                  _inputBox(
                      onlyNum: true,
                      controller: _controller3,
                      title: 'Whatsapp Number:',
                      placeholder: '1111111111'),
                  _inputBox(
                      controller: _controller4,
                      title: 'CPF:',
                      placeholder: 'cdf'),
                  _inputBox(
                      controller: _controller5,
                      title: 'PIX Type:',
                      placeholder: 'PIX Type'),
                  _inputBox(
                      controller: _controller6,
                      title: 'Chave PIX:',
                      placeholder: 'Chave PIX'),

                  // Container(
                  //   margin: EdgeInsets.only(top: 20),
                  //   child: Wrap(
                  //     spacing: 10,
                  //     runSpacing: 10,
                  //     children: _depositAmount(_depositAmounts),
                  //   ),
                  // ),
                  Container(
                    width: Utils().getScreenWidth(context),
                    height: 40,
                    margin: EdgeInsets.only(top: 10),
                    child: ElevatedButton(
                        style: ButtonStyle(
                          backgroundColor:
                              MaterialStateProperty.all(Color(0xFF685BB1)),
                        ),
                        onPressed: () {
                          print(_controller1.text);
                        },
                        child: Text('Withdraw')),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Withdrawal Instructions',
                      style: TextStyle(
                          fontSize: 16,
                          color: Color(0xFFFFED4A),
                          fontWeight: FontWeight.w700),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Number of withdrawals at current VIP level: 1',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Withdrawal fee: 2.5%',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Free monthly withdrawal amount: R\$ 100',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Minimum withdrawal order: R\$ 100',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Maximum withdrawal order: R\$ 500',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Pick-up time: 11:00 - 19:00',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Text(
                      'Payment time: from 5 minutes to 24 hours.',
                      style: TextStyle(
                        color: Colors.white70,
                      ),
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  withdraw() async {
    Map withdrawParam = {
      "transferAmount": '',
    };

    dynamic result = await Api.withdraw(withdrawParam);
    print(result);
  }

  List<Widget> _depositAmount(List list) {
    return list.map((e) {
      return VipRectangleBox(
        width: 100,
        padding: EdgeInsets.only(top: 5, bottom: 6),
        color: Color(0xFF29205F),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('R\$  ',
                style: TextStyle(
                    color: Colors.white, fontWeight: FontWeight.w800)),
            Text('${e['number']}',
                style: TextStyle(
                  color: Colors.white,
                ))
          ],
        ),
      );
    }).toList();
  }

  Widget _inputBox(
      {String? title,
      String? label,
      String? placeholder,
      bool? onlyNum,
      TextEditingController? controller}) {
    return Padding(
      padding: EdgeInsets.only(top: 20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title ?? '',
            style: TextStyle(
                color: Colors.white, fontSize: 14, fontWeight: FontWeight.w700),
          ),
          VipRectangleBox(
            margin: EdgeInsets.only(top: 20),
            alignment: Alignment.centerLeft,
            height: 50,
            color: Color(0xFF29205F),
            child: Row(
              children: [
                Text(
                  label ?? '',
                  style: TextStyle(
                      color: Color(0xFFFFED4A), fontWeight: FontWeight.w800),
                ),
                Expanded(
                  child: TextField(
                    controller: controller,
                    keyboardType: TextInputType.number,
                    inputFormatters: onlyNum != null || onlyNum == true
                        ? [
                          // FilteringTextInputFormatter.allow(RegExp("[0-9.]"))
                          PrecisionLimitFormatter(2)
                          ]
                        : [],
                    cursorColor: Colors.white,
                    style: TextStyle(color: Colors.white),
                    decoration: InputDecoration(
                      border: InputBorder.none,
                    ),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
